﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

namespace lcmyjobs.Web.findjobs
{
    public partial class JobsSearch : BasePage
    {
        lcmyjobs.BLL.adverts ad = new BLL.adverts();
        DataSet ds;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.Title = string.Format("{1}招聘网 {1}人才网 {1}招聘 {1}求职网 {1}猎头网  {0}", Application["webname"].ToString(), Application["webregion"].ToString());
                ds = ad.GetAdvnid(16, 24);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    if (ds.Tables[0].Rows.Count == 9)
                    {
                        for (int i = 0; i < 9; i++)
                        {
                            HyperLink hl = Page.FindControl("HyperLink" + (i + 4).ToString()) as HyperLink;
                            hl.ImageUrl = "~" + ds.Tables[0].Rows[i][0].ToString();
                            hl.NavigateUrl = ds.Tables[0].Rows[i][1].ToString();
                        }

                    }

                }

                if (Application["webid"] != null)
                {
                    int id = Convert.ToInt32(Application["webid"]);
                    Bind("isFrist", id);
                    Bind(id);

                    //Repeater2.DataSource = new lcmyjobs.BLL.news().GetListNews(id, 6, 7);
                    //Repeater2.DataBind(); 

                }


                BindAscx();
            }
        }
        private void BindAscx()
        {
            this.News_jyzd.count = 8;
            this.News_jyzd.typeid = 3;
            this.News_jyzd.length = 18;
            this.News_jyzd.linkname = "<a href='../article-ntid-3.html' class='more_color2' target='_blank'>更多就业指导资讯</a>";
            //this.News_jyzd.linkname = "<span class='more_color2'>更多就业指导资讯</span>";
            //this.News_jyzd.linkurl = "../article-ntid-" + 3 +".html";
            this.News_jyzd.infourl = "../article";
            this.News_jyzd.para = "-" + 3;
            

        }
        private void Bind(int atid)
        {
            int c_isfrist = 0;
            int c_reward = 0;
            int c_vip = 0;
            int c_hunter = 0;
            int c_newjob = 0;
            int c_workerclass = 0;


            DataSet ds = new lcmyjobs.BLL.enterprise_releasejob().GetJobsInfo(true, true, false, false, false, false, atid, 1, 10, out c_isfrist, out c_reward, out c_hunter, out c_vip, out c_newjob, out c_workerclass);

            DataTable dt_isfrist = ds.Tables[0];
            DataTable dt_reward = ds.Tables[1];


            this.gv_isFWinfo.DataSource = dt_isfrist;
            this.gv_isFWinfo.DataBind();

            this.gv_rewardJobs.DataSource = dt_reward;
            this.gv_rewardJobs.DataBind();

        }
        private void Bind(string type, int atid)
        {
            int c_isfrist = 0;
            int c_reward = 0;
            int c_vip = 0;
            int c_hunter = 0;
            int c_newjob = 0;
            int c_workerclass = 0;

            /*
            DataSet ds = new lcmyjobs.BLL.enterprise_releasejob().GetJobsInfo(false, false, false, true, false, false, atid, 1, 20, out c_isfrist, out c_reward, out c_hunter, out c_vip, out c_newjob, out c_workerclass);

            DataTable dt_vip = ds.Tables[0];
            */
            lcmyjobs.BLL.enterprise_releasejob r = new BLL.enterprise_releasejob();
            DataSet ds_Vip = r.GetIndexInfoVip(60, atid);


            //绑定ＶＩＰ职位
            #region vip职位

            if (ds_Vip.Tables[0].Rows.Count > 0)
            {
                int num = ds_Vip.Tables[0].Rows.Count;

                StringBuilder str1 = new StringBuilder("<ul>");
                StringBuilder str2 = new StringBuilder("<ul>");
                for (int i = 0; i < num; i++)
                {
                    DataRow row = ds_Vip.Tables[0].Rows[i];

                    if (i % 2 > 0)
                    {
                        SetVipJobs(str2, row);
                    }
                    else
                    {
                        SetVipJobs(str1, row);
                    }

                }
                str1.Append("</ul>");
                str2.Append("</ul>");
                this.lti_vipL.Text = str1.ToString();
                this.lti_vipR.Text = str2.ToString();
            }

            #endregion



        }
        /*
        private void BindVipJobs(DataTable dt_vip)
        {
            StringBuilder str = new StringBuilder("");
            
            #region 绑定

            str.Append("<ul class='vpzp_xx'>");
            if (dt_vip.Rows.Count > 0)
            {
                foreach (DataRow row in dt_vip.Rows)
                {
                    str.Append("<li>");
                    str.Append("<span class='xsvp'>VIP</span>");
                    str.Append("<a target='_blank' style='color:#1e6db0;' href='../findjobs/ListVipJobs-");
                    str.Append(row["enterprise_bid"]);
                    str.Append(".html");
                    str.Append("'>");
                    str.Append(GetZW(row["name"].ToString(), 15));
                    str.Append("</a>&nbsp;&nbsp;&nbsp;");
                    str.Append(row["jobs_name"]);
                    str.Append("</li>");
                }
               
            }
            str.Append("</ul>");

            #endregion

            this.lti_vipJobs.Text = str.ToString();
        }
        */
        public string GetBH(string str)
        {
            return "<span style='padding-right:5px;color:#ff6600; font-weight:bold;'>赏</span>" + str.ToString().PadLeft(6, '0');
        }

        public string GetZW(string str, int length)
        {
            if (str.Length > length)
            {
                return str.Substring(0, length) + "...";
            }
            else
            {
                return str;
            }
        }


        protected void gv_isFWinfo_RowCreated(object sender, GridViewRowEventArgs e)
        {

        }

        protected void gv_isFWinfo_RowDataBound(object sender, GridViewRowEventArgs e)
        {

        }

        private void SetVipJobs(StringBuilder str, DataRow row)
        {
            string jobsNameList = row["jobs_namelist"].ToString();
            string[] jls = jobsNameList.Split('|');
            string jobs_name = "";

            // 获取企业所发布的3个职位名称,如果不够3个职位，则获取所有职位
            if (jls.Length > 3)
            {
                for (int j = 0; j < 3; j++)
                {
                    jobs_name += jls[j].Split('-')[0] + "  ";
                }
            }
            else
            {
                for (int j = 0; j < jls.Length; j++)
                {
                    jobs_name += jls[j].Split('-')[0] + "  ";
                }
            }
            str.Append("<li>&nbsp;<a target='_blank' href='../findjobs/ListVipJobs-");
            str.Append(row["enterprise_bid"]);
            str.Append(".html");
            str.Append("' onmouseover='showMessage(this,\"" + jobsNameList + "\")'>");
            str.Append("[");
            str.Append(GetStrSub(row["name"].ToString(), 12));
            str.Append("]");
            str.Append("</a>&nbsp;&nbsp;");
            str.Append(GetStrSub(jobs_name, 10));
            str.Append("<span></span></li>");
        }

        private string GetStrSub(string str, int length)
        {
            if (str.Length > length)
            {
                return str.Substring(0, length) ;
            }
            else
            {
                return str;
            }
        }
    }
}